<cfparam name="url.expire" default="false">
<cfparam name="url.updateCreatedDate" default="false">


<cfif url.expire eq "true">
	<cfset application.objectCache.expireCacheForPrefix("sample-prefix")>
</cfif>

<h1>CFObjectCache</h1>

<a href="index.cfm">Reload</a>

<p>CFObjectCache is a wrapper around ColdFusion 9's &lt;cfcache&gt; tag which includes support for prefixes (namespaces).</p>

<cfset dateNow = now()>
<cfset cachedDate = dateNow>
<cfset cacheUntil = DateAdd("n",2,dateNow)>
<cfset lastUpdated = CreateDate(2001,1,1)> <!--- Set to a date in the past --->
<cfif url.updateCreatedDate eq true> 
	<cfset lastUpdated = now()>
</cfif>

<h2>Demo 1 - Object with Expiry Time</h2>

<p>For this demo we generated the current date, which is: <cfoutput>#dateNow#</cfoutput></p>

<p>The first time the page is loaded, we store this date to the cache, with an expiry time of 2 mins.</p>

<p>Subsequent views within that 2 minute period will show the time of the initial access.  If the 2 mins has passed, 
	the date will be refreshed.</p>

<p><cf_textcache objName="sample-prefix.date1" cacheUntil="#cacheUntil#">
   Date1 - : <cfoutput>#dateNow#</cfoutput>
</cf_textcache></p>

<h2>Demo 2 - Object with last updated check</h2>

<p>The "lastUpdated" attribute can be used to check whether or not an object needs to be regenerated.  I generally use this to compare again a "last_updated" 
time to determine whether or not something needs to be generated.</p>

<p>For this example we will continue to get the date from the cache, until the lastUpdated time becomes greater than the createdDate.  
    <a href="index.cfm?updateCreatedDate=true">Click here to reset it.</a></p>

<p><cf_textcache objName="sample-prefix.date2" createdDate="#dateNow#" lastUpdated="#lastUpdated#">
   Date 2 - : <cfoutput>#dateNow#</cfoutput>
</cf_textcache></p>

<h2>Demo 3 - Flush Cache</h2>

<p><a href="index.cfm?expire=true">By clicking this link </a> all cached objects on this page will be expired and reloaded.  
The expire is done by calling the "expireCacheForPrefix" function, and passing through the prefix for each the cached objects, 
which in this case is "sample-prefix".</p>

<cfif url.expire eq "true">
	<p><strong>Data was expired.</strong></p>
</cfif>
